import axios from 'axios'

const http = axios.create({
  baseURL: process.env.API_ORIGIN,
})
http.interceptors.request.use(
  function (config) {
    // 在发送请求之前做些什么
    config.headers.platform = process.env.PLATFORM
    return config
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error)
  }
)
http.interceptors.response.use(
  function (response) {
    if (response.data && response.data.code === 200) {
      return response.data
    }
    return Promise.reject(response.data)
  },
  function (error) {
    console.log(error)
    return Promise.reject(error)
  }
)
export default http
